package com.netty.demo;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @Created on 2021/4/13.
 * @Author by zbk
 * @Description:
 */
public class TestGatheringWrite {

    public static void main(String[] args) {

        ByteBuffer buffer1 = StandardCharsets.UTF_8.encode("one");
        ByteBuffer buffer2 = StandardCharsets.UTF_8.encode("two");
        ByteBuffer buffer3 = StandardCharsets.UTF_8.encode("three");

        try (FileChannel fileChannel = new RandomAccessFile("data3.txt", "rw").getChannel()) {

            fileChannel.write(new ByteBuffer[]{buffer1, buffer2, buffer3});


            System.out.println(fileChannel.size());// 获取大小

            fileChannel.force(true);// 签字写入文件和元数据，对性能有影响


        }catch (Exception e){

        }


    }

}
